{extend name="public/base"}
{block name='main'}
<style type="text/css">
    .red {color: #FF5722!important;}
    .green {color: #5FB878!important;}
</style>
<fieldset class="layui-elem-field layui-field-title" style="margin-top:0px;">
    <legend>{$menuid|getmenuname}</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="">
    <input type="hidden" name="menuid" value="67" />
    <div class="my-btn-box"> <span class="fl">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">所属栏目</label>
        <div class="layui-input-inline">
          <select name="cid">
            <option value=""></option>
                {volist name="catelist" id="val" }
                       <option value="{$val.id}" {eq name="$searchArr.cid|default=''" value="$val.id"}selected="selected"{/eq}>{$val.name}</option>
                        {volist name="val['erji']" id="vo"}
                           <option value="{$vo.id}" {eq name="$searchArr.cid|default=''" value="$vo.id"}selected="selected"{/eq}>&nbsp;&nbsp;&nbsp;├─ {$vo.name}</option>
                        {/volist}
                    {/volist}
          </select>
        </div>

        <label class="layui-form-label">关键词</label>
        <div class="layui-input-inline">
          <input type="tel" name="title" placeholder="文档关键词" lay-verify="required" value="{$searchArr.title|default=''}" class="layui-input">
        </div>
        <div class="layui-input-inline">
          <button class="layui-btn mgl-20">搜索</button>
        </div>
      </div>
    </div>
    </span>
        <span class="fr">
        <a href="{:url('convert/index', array('menuid'=>1))}" class="layui-btn mgl-20">显示全部</a>
        <a class="layui-btn layui-btn-danger" id="btn-alldel001">批量转换</a>
        </span> </div>
</form>
<form class="layui-form layui-form-pane" action="">
    <table class="layui-table">
        <colgroup>
            <col width="60">
            <col width="50">
            <col width="">
            <col width="120">
            <col width="120">
            <col width="120">
            <col width="80">
            <col width="150">
            <col width="100">
            <col width="80">
            <col width="100">
        </colgroup>
        <thead>
        <tr>
            <th><input type="checkbox" id="checkall_t" lay-skin="primary" lay-filter="allChoose" ></th>
            <th>ID</th>
            <th>文档标题</th>
            <th>所属栏目</th>
            <th>上传时间</th>
            <th>是否转换</th>
            <th>管理操作</th>
        </tr>
        </thead>
        <tbody id="userList">
        {volist name="list" id="val" }
            <tr>
                <td><input class="doc_checkbox" type="checkbox" value="{$val.id}" lay-skin="primary" lay-filter="itemChoose"></td>
                <td>{$val.id}</td>
                <td><a href="{:url('home/doc/doccon',array('id'=>$val['id']))}" target="_blank">{$val.title}</a></td>
                 <td>{$cate_list[$val['cid']]}</td>
                <td>{$val.create_time|date='Y-m-d H:i'}</td>
                <td>
                    {$val.convert_status_text}
                </td>

                <td>
                    <a href="javascript:void(0);" class="J_confirmurl" data-acttype="ajax" data-uri="{:url('convert/convert', array('id'=>$val['id']))}" id="convert_btn" >转换</a>
                </td>
            </tr>
        {/volist}

        </tbody>
    </table>
</form>
<div id="test-laypage-demo0">
    <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-29">
        {$list|raw}
    </div>
</div>

<script>
    layui.use(['layer','jquery','form','element','table'], function () {
        var $ =layui.$;
        $('#btn-alldel001').click(function(){
            layer.msg('别点击了，暂时没批量转换这功能', {
                time: 2500
            });
        })
        $('#convert_btn').click(function(){
            var url = $(this).attr('data-uri');
            var index = layer.open({
              type: 1
              , title: '转换文件'
              , area: '330px'
              , shade: 0.1
              , shadeClose: true
              , content: '<blockquote class="layui-elem-quote">文件转换中，' +
                    '<span class="layui-bg-red">请不要关闭此页面</span> </div>'
            });
            //倒计时
            var flag = 1;    //秒
            var num = 20;
             // alert(flag);
            var lastInterval = setInterval(function () {
                num -=1;
                if (flag == 0) {
                    clearInterval(lastInterval);
                    window.location.reload();
                   // alert('成功');
                    console.log('0000');
                }else if(flag == 2 || num==0){
                    clearInterval(lastInterval);
                    layer.close(index);
                    layer.msg('转换失败，请刷新页面重新操作', {
                        time: 1800
                    });
                }else{
                    // alert(44);
                    console.log('kkkk');
                    $.get(url,function(res){
                        if(res.status == 1){
                            flag = 0;
                            // alert('haole');
                            layer.msg('上传成功', {
                                time: 500
                            });
                            window.location.reload();
                            console.log('1111');
                        }else if(res.status == 2){
                            flag = 2;
                        }else{
                            flag = 3;
                            return false;
                            // alert(res);
                        }

                    });
                }
            }, 3000);
        })



        //编辑弹窗
        Oper.config.edit.height = '300px';
        Oper.config.edit.height = '520px';

        //参数：layui、名称、模块名、主键（删除用）
        Oper.initList(layui, '文档', 'convert', 'id');

    });
</script>

{/block}